package ecom;

import ecom.perssistance.HibernateFactory;
import java.io.FileOutputStream;
import java.sql.Connection;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.hibernate.Session;

public class DatabaseExport {

    public static void main(String[] args) throws Exception {
        // database connection
        HibernateFactory.buildIfNeeded();
        Session session = HibernateFactory.openSession();
        Connection conn = session.connection();
        IDatabaseConnection connection = new DatabaseConnection(conn);

        // Export en XML
        IDataSet dataSet = connection.createDataSet();
        FlatXmlDataSet.write(dataSet, new FileOutputStream("src/conf/dbunit/database_schema.xml"));
    }
}
